package com.example.park.service.impl;

import com.example.park.dao.ParkShareDao;
import com.example.park.entity.ParkShareEntity;
import com.example.park.entityVO.ParkShareDimVO;
import com.example.park.entityVO.ParkShareVO;
import com.example.park.service.ParkShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParkShareServiceImpl implements ParkShareService {

    @Autowired
    private ParkShareDao parkShareDao;

    @Override
    public List<ParkShareVO> queryByParam(ParkShareVO vo) {
        return parkShareDao.queryVOByParam(vo);
    }

    @Override
    public List<ParkShareVO> queryByUid(Integer uId) {
        return parkShareDao.queryVOByUid(uId);
    }

    @Override
    public List<ParkShareVO> queryById(Integer id) {
        return parkShareDao.queryVOById(id);
    }

    @Override
    public List<ParkShareVO> queryByDim(ParkShareDimVO vo) {
        return parkShareDao.queryVOByDim(vo);
    }

    @Override
    public String pushTime(ParkShareEntity ps) {
        List<ParkShareEntity> vos = parkShareDao.queryByParam(ps);
        if (vos.size() > 0) {
            return "时间段选择错误！";
        }
        if (parkShareDao.insert(ps) > 0) {
            return "发布成功！";
        }
        return "发布失败！";
    }

    @Override
    public boolean insert(ParkShareEntity parkShareEntity) {
        return parkShareDao.insert(parkShareEntity) > 0;
    }

    @Override
    public boolean update(ParkShareEntity parkShareEntity) {
        ParkShareVO parkShareVO = parkShareDao.queryVOById(parkShareEntity.getId()).get(0);
        if (parkShareVO.getuId() != null) {
            return false;
        }
        return parkShareDao.update(parkShareEntity) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return parkShareDao.delete(id) > 0;
    }
}
